package com.example.yjhticket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.yjhticket.entity.Tickets;
import com.example.yjhticket.mapper.OrdersMapper;
import com.example.yjhticket.mapper.TicketsMapper;
import com.example.yjhticket.service.OrderService;
import com.example.yjhticket.entity.Orders;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    OrdersMapper ordersMapper;


    @Override
    public int addOrder(Orders orders) {
        return ordersMapper.insert(orders);
    }

    @Override
    public List<Orders> getOrderByID(String id) {
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",id);

        final List<Orders> orders = ordersMapper.selectList(wrapper);
        for (Orders order : orders) {
            final Tickets ticketsByd = ordersMapper.getTicketsByd(order.getTicketId().toString());
            order.setTickets(ticketsByd);
        }
        return orders;
    }
}
